<template>
  <div class="userinfo">
    <img class="avatar" :src="avatar"></img>
    <div class="nickname">{{user_id}}</div>
    <div class="id">用户ID：{{uid}}</div>
    <div class="vip" v-if="is_vip==0">
      <div >您当前还不是VIP哦～</div>
      <div class="vip-open" @click="openVip()">马上开通</div>
    </div>
    <div class="vip" v-else>
      <div >会员于{{is_vip==1 ? unlock_end_time_text: advanced_end_time_text }}到期～</div>
      <div class="vip-open" @click="openVip()">点击续费</div>
    </div>
    <div class="options">
      <div class="option" v-for="(item, index) in options" :key="item.name" :class="item.path == $route.path ? 'active-option' : ''">
        <i class="icon" :class="item.icon"></i>
        <a :href="item.path">{{item.name}}</a>
      </div>
    </div>
    <payform
      style="z-index: 9999"
      v-if="showPay"
      @closeDialog="closeDialog"
      :description="''"
      :showCloseButton="true"
      :mtips="'开通vip，解锁更多特权'"
    ></payform>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import payform from "../components/paycomp.vue";

export default {
  data() {
    return {
      options: [
        // {
        //   name: "成为VIP",
        //   icon: "el-icon-bank-card",
        //   path: "/user/index",
        // },
        { name: "个人信息", icon: "el-icon-user", path: "/user/userinfo" },
        { name: "我的订单", icon: "el-icon-goods", path: "/user/order" },
        { name: "我的阅读", icon: "el-icon-document", path: "/user/history" },
        { name: "我的下载", icon: "el-icon-download", path: "/user/download" },
        { name: "我的收藏", icon: "el-icon-star-off", path: "/user/favorite" },
        { name: "我的邀请", icon: "el-icon-share", path: "/user/invite" },
      ],
      showPay: false,
    };
  },
  computed: {
    ...mapGetters([
      "sid",
      "uid",
      "user_id",
      "is_vip",
      "name",
      "avatar",
      "showLogin",
      "phone",
      "unlock_end_time_text",
      "advanced_end_time_text",
    ]),
  },
  props: {
    value: {
      type: Boolean,
      default: false,
    },
  },
  components: { payform },
  created() {},
  methods: {
    openVip() {
      this.showPay = true;
    },
    closeDialog() {
      this.showPay = false;
    },
  },
};
</script>

<style lang="less" scoped>
.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 20px;
}

.top {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar {
  margin-top: 40px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
}
.nickname {
  margin-top: 20px;
  font-size: 16px;
  color: #333;
  font-weight: 700;
}

.id {
  font-size: 13px;
  color: #333;
  margin-top: 20px;
}

.vip {
  margin-top: 20px;
  color: #3370ff;
  font-size: 13px;
  display: flex;
  align-items: center;
}

.vip-open {
  margin-left: 10px;
  background: #3370ff;
  color: white;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.options {
  margin-top: 40px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.option {
  width: 100%;
  display: flex;
  align-items: center;
  height: 48px;
  a {
    text-decoration: none;
    background-color: transparent;
    outline: none;
    cursor: pointer;
    transition: color 0.3s;
    color: #333;
    font-size: 14px;
  }
}

.active-option {
  color: #388ae9;
  background: rgba(51, 115, 212, 0.1);
  border-right: 3px solid #388ae9;
  a {
    color: #388ae9;
  }
}

.icon {
  margin-left: 80px;
  width: 18px;
  height: 18px;
  margin-right: 8px;
}
</style>